var AjaxBroker = Class.create();
AjaxBroker.prototype = {
	initialize : function(url, methodType, successListener, failureListener) {
		
		this.ajaxRequest = null;
		this.successListener = successListener;
		this.failureListener = failureListener;
		this.methodType = methodType;
		this.url = url;
	
		this.successCallback = function(response) {

			try {
				this.successListener(response.responseXML);
			} catch (e) {
				Logger.debug("AjaxBroker successCallback"+e);
			}
			this.ajaxRequest =null;
		}.bind(this);
		
		this.failCallback = function(response) {
			if (typeof this.failureListener !== UNDEFINED) {
				alert(response.responseText)
				this.failureListener(response.responseText)
			}
			this.ajaxRequest =null;
		}.bind(this);

	},
	
	call : function() {
		this.ajaxRequest = new Ajax.Request(this.url, {
			method :this.methodType,
			asynchronous :true,
			onSuccess :this.successCallback,
			onFailure :this.failCallback,
			onException : function(request, exception) {
				Logger.debug(exception);
			}
		});

	}
};

